﻿@inject NavigationManager NavigationManager
@inject IDataCacheService _dataCacheService

@if (CatalogItems != null && CatalogItems.Any() && string.IsNullOrWhiteSpace(Url) == false)
{
    <MMenu OffsetY @bind-Value="menu" Top>
     <ActivatorContent Context="m">
         <MTooltip Bottom>
             <ActivatorContent Context="c">
                 @{
                        var attrs = new Dictionary<string, object>();
                        m.Attrs.ToList().ForEach(item => attrs[item.Key] = item.Value);
                        c.Attrs.ToList().ForEach(item => attrs[item.Key] = item.Value);
                    }
                    @if (Kanban)
                    {
                        <button class="float-button" @attributes="@attrs">
                            <img src="./_content/CnGalWebSite.Kanban/images/catalog.png" draggable="false" />
                        </button>
                    }
                    else
                    {
                        <MButton Fab Small Color="primary" Class="@Class" @attributes="@attrs">
                             <MIcon>mdi-format-list-bulleted-square </MIcon>
                         </MButton>

                    }
                </ActivatorContent>
                <ChildContent>
                    <span>目录</span>
                </ChildContent>
            </MTooltip>
        </ActivatorContent>

        <ChildContent>
            <MDCard Style="width:400px;">
                <div class="w-100">
                    <CnGalWebSite.Shared.MasaComponent.Shared.Components.Catalogs.MasaCatalog CatalogItems="CatalogItems" Url="@Url" @ref="masaCatalog" />
                </div>
            </MDCard>
        </ChildContent>
    </MMenu>
}

@code {

    [Parameter]
    public string Class { get; set; }

     [Parameter]
    public bool Kanban { get; set; }

    public string Url { get; set; }

    private bool menu { get; set; }

    CnGalWebSite.Shared.MasaComponent.Shared.Components.Catalogs.MasaCatalog masaCatalog;
    List<ArticleCatalogModel> CatalogItems = new List<ArticleCatalogModel>();

    public void Refresh(string text, string url)
    {
        Url = url;
        CatalogItems = text.GetCatalog();

        StateHasChanged();

    }
}
